package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@Slf4j
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	@Operation(summary = "获取用户信息-feign")
	@GetMapping(value = "findUserInfoById/{userId}")
	public Result<UserInfo> findUserInfoById(@PathVariable(value = "userId") Long userId){
		UserInfo userInfo = userInfoService.getById(userId);
		return Result.ok(userInfo);
	}

	@GuiguLogin(required = true)
	@Operation(summary = "判断用户是否购买声音列表-feign ")
	@PostMapping("userIsPaidTrack/{albumId}")
	public Result<Map<Long,Integer>> userIsPaidTrack(@PathVariable(name = "albumId") Long albumId,
													 @RequestBody List<Long> trackIds) {
		Map<Long,Integer> map =userInfoService.userIsPaidTrack(albumId,trackIds);
		return Result.ok(map);

	}

	@GetMapping(value = "/findUserInfoVoByUserId/{userId}")
	public Result<UserInfoVo> findUserInfoVoByUserId(@PathVariable(value = "userId") Long userId) {
		UserInfoVo userInfoVo = userInfoService.findUserInfoVoByUserId(userId) ;
		return Result.ok(userInfoVo) ;
	}

	@GuiguLogin
	@Operation(summary = "根据专辑id获取用户支付过的声音id列表-Feign")
	@GetMapping("/findUserPaidTrackList/{albumId}")
	public Result<List<Long>> findUserPaidTrackList(@PathVariable(name = "albumId") Long albumId){

		List<Long> trackIdList = userInfoService.findUserPaidTrackList(albumId);
		return Result.ok(trackIdList);
	}

	@GetMapping(value = "/updateVipExpireStatus")
	public Result updateVipExpireStatus() {
		userInfoService.updateVipExpireStatus();
		log.info("更新vip失效状态成功了....");
		return Result.ok() ;
	}



}

